#ifndef ACCOUNT_H
#define ACCOUNT_H

#include <QList>
#include <QString>
#include <QObject>
#include <QMap>

class QSettings;
class QNetworkReply;
class QNetworkAccessManager;
class PluginBase;
class Account : public QObject
{

Q_OBJECT
public:
    Account(QObject* parent = 0);

    int uid;
    QString name;
    QString user;
    QString pwd;
    QString cookies;
    bool active;
    QString loginKey;

    bool login;
    uint loginTime;
    bool netReady;
    QNetworkAccessManager* net;
    QNetworkReply* rsp;

    void updateCookies();

    void updateView();
public slots:
    void netFinished();
    void doTask();
};

class Task;
class AccountManager : public QObject
{
Q_OBJECT
private:
    static AccountManager* me;
    QSettings* settings;

    AccountManager():QObject(NULL), settings(NULL){};
    ~AccountManager(){};
public:
    QMap<uint, Account*> actMap;

    static AccountManager* self(){return me?me:(me = new AccountManager());}
    void setSettings(QSettings* settings);
    Account* account(int uid){return actMap.value(uid);}
    int addNewAccount(QString user, QString pwd);
    bool load();
    bool save();

signals:
    void updated();
public slots:
    void addNewAccountFinished(Task*);
};


#endif // ACCOUNT_H
